﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using EF.Util.DBUtility;

namespace EF.DAL.Base
{
    /// <summary>
    ///  
    /// </summary>
    public class LangDAO
    {
        /// <summary>
        /// 根据标记获取语言
        /// </summary>
        /// <param name="marks">标记字符串('new','index')</param>
        /// <param name="lang">语言(zh-cn,en-us,ja)</param>
        /// <returns></returns>
        public DataTable GetLang(string marks, string lang)
        {
            SqlParameter[] sqlparams = {
                                           new SqlParameter("@marks", SqlDbType.NVarChar,1000),
                                           new SqlParameter("@lang", SqlDbType.NVarChar, 50)
                                       };

            sqlparams[0].Value = marks;
            sqlparams[1].Value = lang;

            SqlDataReader dr = DbHelperSQL.RunProcedure("spBaseLangGet", sqlparams);
            DataTable rowcol = new DataTable("rowcol");
            rowcol.Load(dr);
            dr.Close();

            DataTable colrow = new DataTable("colrow");

            for (int i = 0; i < rowcol.Rows.Count; i++)
            {
                DataColumn dc = new DataColumn(rowcol.Rows[i][0].ToString(), typeof(string));
                colrow.Columns.Add(dc);
            }

            DataRow row = colrow.NewRow();
            for (int i = 0; i < rowcol.Rows.Count; i++)
            {
                row[i] = rowcol.Rows[i][1].ToString();
            }
            colrow.Rows.InsertAt(row, 0);

            return colrow;
        }
    }
}
